<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="SSM,Spring,SpringMVC,Mybatis,Maven," />





  <link rel="alternate" href="/atom.xml" title="Hfbin Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="在整合之前先介绍一下Maven: Maven是一个项目管理工具，它包含了一个项目对象模型 (Project Object Model)，一组标准集合，一个项目生命周期(Project Lifecycle)，一个依赖管理系统(Dependency Management System)，和用来运行定义在生命周期阶段(phase)中插件(plugin)目标(goal)的逻辑。当你使用Maven的时候，你">
<meta name="keywords" content="SSM,Spring,SpringMVC,Mybatis,Maven">
<meta property="og:type" content="article">
<meta property="og:title" content="Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合">
<meta property="og:url" content="http://yoursite.com/2017/10/31/Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合/index.html">
<meta property="og:site_name" content="Hfbin Blog">
<meta property="og:description" content="在整合之前先介绍一下Maven: Maven是一个项目管理工具，它包含了一个项目对象模型 (Project Object Model)，一组标准集合，一个项目生命周期(Project Lifecycle)，一个依赖管理系统(Dependency Management System)，和用来运行定义在生命周期阶段(phase)中插件(plugin)目标(goal)的逻辑。当你使用Maven的时候，你">
<meta property="og:locale" content="en">
<meta property="og:image" content="http://img.blog.csdn.net/20171027015015915?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027020331178?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027020342153?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027020354516?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027020404022?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027020436211?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027020654010?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027022437583?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027022448076?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027022458171?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027022510544?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027023454691?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027095142552?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027095656598?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027101137204?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027101812625?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027110002365?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20171027110436398?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:updated_time" content="2017-11-03T17:26:11.069Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合">
<meta name="twitter:description" content="在整合之前先介绍一下Maven: Maven是一个项目管理工具，它包含了一个项目对象模型 (Project Object Model)，一组标准集合，一个项目生命周期(Project Lifecycle)，一个依赖管理系统(Dependency Management System)，和用来运行定义在生命周期阶段(phase)中插件(plugin)目标(goal)的逻辑。当你使用Maven的时候，你">
<meta name="twitter:image" content="http://img.blog.csdn.net/20171027015015915?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: 'FQWD7RL0XS',
      apiKey: 'ad0b6762f0b7721176ce7c215ba85c58',
      indexName: 'hfbin',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>

<script>
    (function(){
        if(''){
            if (prompt('该文章博主已加密') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>


  <link rel="canonical" href="http://yoursite.com/2017/10/31/Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合/"/>

    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
	<link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
<style>
    .pace .pace-progress {
        background: #1E92FB; /*进度条颜色*/
        height: 3px;
    }
    .pace .pace-progress-inner {
         box-shadow: 0 0 10px #1E92FB, 0 0 5px     #1E92FB; /*阴影颜色*/
    }
    .pace .pace-activity {
        border-top-color: #1E92FB;    /*上边框颜色*/
        border-left-color: #1E92FB;    /*左边框颜色*/
    }
</style>

	


  <title>Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合 | Hfbin Blog</title>
  












  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1266987503&web_id=1266987503" language="JavaScript"></script>
  </div>





</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

 
    

  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script type="text/javascript" src="/js/src/algolia.js?v=5.1.2"></script>

  
  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"></span>
        <span class="site-title">Hfbin Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">My friend promised me to go if I had the road</p>
      
  </div>

  <div class="site-nav-toggle" style="position: absolute; float: left; ">
    <button>
      <span class="btn-bar" style="background: #fff;"></span>
      <span class="btn-bar" style="background: #fff;"></span>
      <span class="btn-bar" style="background: #fff;"></span>
    </button>
  </div>
</div>

<nav class="site-nav" >
  <!-- set hasSearch = theme.swiftype_key || theme.algolia_search.enable || theme.tinysou_Key || theme.local_search.enable % -->
  	


  
    <ul id="menu" class="menu" >
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
			 <!-- 增加下面语句 -->
		  
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/31/Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="HuangFuBin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars3.githubusercontent.com/u/26451830?s=400&u=fac2b4c7903b3ad1210b530e2d18e42fcb410b0a&v=4">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hfbin Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-10-31T16:37:01+08:00">
                2017-10-31
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/SSM-Maven/" itemprop="url" rel="index">
                    <span itemprop="name">SSM+Maven</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/2017/10/31/Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合/#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2017/10/31/Maven+SSM（SpringMVC+Spring+Mybatis） 框架整合/" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="在整合之前先介绍一下Maven"><a href="#在整合之前先介绍一下Maven" class="headerlink" title="在整合之前先介绍一下Maven:"></a><strong>在整合之前先介绍一下Maven:</strong></h4><blockquote>
<p>Maven是一个项目管理工具，它包含了一个项目对象模型 (Project Object Model)，一组标准集合，一个项目生命周期(Project Lifecycle)，一个依赖管理系统(Dependency Management System)，和用来运行定义在生命周期阶段(phase)中插件(plugin)目标(goal)的逻辑。当你使用Maven的时候，你用一个明确定义的项目对象模型来描述你的项目，然后Maven可以应用横切的逻辑，这些逻辑来自一组共享的（或者自定义的）插件。<br> Maven 有一个生命周期，当你运行 mvn install 的时候被调用。这条命令告诉 Maven 执行一系列的有序的步骤，直到到达你指定的生命周期。遍历生命周期旅途中的一个影响就是，Maven 运行了许多默认的插件目标，这些目标完成了像编译和创建一个 JAR 文件这样的工作。<br>此外，Maven能够很方便的帮你管理项目报告，生成站点，管理JAR文件，等等。：</p>
</blockquote>
<p>常用命令:</p>
<blockquote>
<p>mvn archetype:generate 创建Maven项目<br>mvn compile 编译源代码<br>mvn deploy 发布项目<br>mvn test-compile 编译测试源代码<br>mvn test 运行应用程序中的单元测试<br>mvn site 生成项目相关信息的网站<br>mvn clean 清除项目目录中的生成结果<br>mvn package 根据项目生成的jar<br>mvn install 在本地Repository中安装jar<br>mvn eclipse:eclipse 生成eclipse项目文件<br>mvnjetty:run 启动jetty服务<br>mvntomcat:run 启动tomcat服务<br>mvn clean package -Dmaven.test.skip=true:清除以前的包后重新打包，跳过测试类</p>
</blockquote>
<p>好Maven就介绍到这里！！！</p>
<h4 id="Spring-SpringMVC-Mybatis基本概念"><a href="#Spring-SpringMVC-Mybatis基本概念" class="headerlink" title="Spring SpringMVC Mybatis基本概念"></a><strong>Spring SpringMVC Mybatis基本概念</strong></h4><p>1、Spring</p>
<pre><code>Spring是一个开源框架，Spring是于2003 年兴起的一个轻量级的Java 开发框架，由Rod Johnson 在其著作Expert One-On-One J2EE Development and Design中阐述的部分理念和原型衍生而来。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而，Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言，任何Java应用都可以从Spring中受益。 简单来说，Spring是一个轻量级的控制反转（IoC）和面向切面（AOP）的容器框架。
</code></pre><p>2、SpringMVC</p>
<pre><code>Spring MVC属于SpringFrameWork的后续产品，已经融合在Spring Web Flow里面。Spring MVC 分离了控制器、模型对象、分派器以及处理程序对象的角色，这种分离让它们更容易进行定制。
</code></pre><p>3、MyBatis</p>
<pre><code>MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code，并且改名为MyBatis 。MyBatis是一个基于Java的持久层框架。iBATIS提供的持久层框架包括SQL Maps和Data Access Objects（DAO）MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis 使用简单的 XML或注解用于配置和原始映射，将接口和 Java 的POJOs（Plain Old Java Objects，普通的 Java对象）映射成数据库中的记录。
</code></pre><h4 id="SSM整合在这使用的开发工具是idea"><a href="#SSM整合在这使用的开发工具是idea" class="headerlink" title="SSM整合在这使用的开发工具是idea"></a><strong>SSM整合在这使用的开发工具是idea</strong></h4><p>新建一个maven工程（在这就省略了）：</p>
<blockquote>
<p>在这说明一点创建完之后文件夹有些不完整需要自己创建java源文件目录还有测试（test）目录</p>
</blockquote>
<h5 id="先从pom-xml文件入手"><a href="#先从pom-xml文件入手" class="headerlink" title="先从pom.xml文件入手"></a><strong>先从pom.xml文件入手</strong></h5><p>具体需要加入什么jar，看自己的功能所需 , 可以到官网查<a href="https://mvnrepository.com" target="_blank" rel="external">https://mvnrepository.com</a></p>
<p>下面是我pom.xml的内容（包括spring+springmvc+mybatis等相关jar包）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div></pre></td><td class="code"><pre><div class="line">&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</div><div class="line">         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;</div><div class="line">    &lt;parent&gt;</div><div class="line">        &lt;artifactId&gt;idea_maven&lt;/artifactId&gt;</div><div class="line">        &lt;groupId&gt;com.hfbin.maven&lt;/groupId&gt;</div><div class="line">        &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;</div><div class="line">    &lt;/parent&gt;</div><div class="line">    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;</div><div class="line">    &lt;artifactId&gt;idea_maven01&lt;/artifactId&gt;</div><div class="line">    &lt;packaging&gt;war&lt;/packaging&gt;</div><div class="line">    &lt;name&gt;idea_maven01 Maven Webapp&lt;/name&gt;</div><div class="line">    &lt;url&gt;http://maven.apache.org&lt;/url&gt;</div><div class="line">    &lt;dependencies&gt;</div><div class="line"></div><div class="line">        &lt;!-- ueditor 编辑器--&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/cn.songxinqiang/com.baidu.ueditor --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;cn.songxinqiang&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;com.baidu.ueditor&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;1.1.2-offical&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.json/json --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.json&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;json&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;20160810&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line"></div><div class="line">        &lt;!-- 文件上传--&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;1.3.1&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;commons-codec&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;1.10&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!--引入pageHelper分页插件 --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;com.github.pagehelper&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;pagehelper&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;5.0.0&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!-- MBG --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.mybatis.generator&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;mybatis-generator-core&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;1.3.5&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!-- 返回json字符串的支持 --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;2.8.8&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!--JSR303数据校验支持；tomcat7及以上的服务器，</div><div class="line">        tomcat7以下的服务器：el表达式。额外给服务器的lib包中替换新的标准的el</div><div class="line">        --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;5.4.1.Final&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line"></div><div class="line">        &lt;!-- Spring-Jdbc --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!--Spring-test --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-test --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;spring-test&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line"></div><div class="line">        &lt;!-- Spring面向切面编程 --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!--MyBatis --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.mybatis&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;mybatis&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;3.4.2&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line">        &lt;!-- MyBatis整合Spring的适配包 --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;org.mybatis&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;mybatis-spring&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;1.3.1&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!-- 数据库连接池、驱动 --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/c3p0/c3p0 --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;c3p0&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;c3p0&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;0.9.1&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;mysql&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;5.1.41&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line">        &lt;!-- （jstl，servlet-api，junit） --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/jstl/jstl --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;jstl&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;jstl&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;1.2&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;javax.servlet&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;3.0.1&lt;/version&gt;</div><div class="line">            &lt;scope&gt;provided&lt;/scope&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">        &lt;!-- junit --&gt;</div><div class="line">        &lt;!-- https://mvnrepository.com/artifact/junit/junit --&gt;</div><div class="line">        &lt;dependency&gt;</div><div class="line">            &lt;groupId&gt;junit&lt;/groupId&gt;</div><div class="line">            &lt;artifactId&gt;junit&lt;/artifactId&gt;</div><div class="line">            &lt;version&gt;4.12&lt;/version&gt;</div><div class="line">        &lt;/dependency&gt;</div><div class="line"></div><div class="line">    &lt;/dependencies&gt;</div><div class="line">    &lt;build&gt;</div><div class="line">        &lt;finalName&gt;mybatis_generator&lt;/finalName&gt;</div><div class="line">        &lt;plugins&gt;</div><div class="line">            &lt;plugin&gt;</div><div class="line">                &lt;groupId&gt;org.mybatis.generator&lt;/groupId&gt;</div><div class="line">                &lt;artifactId&gt;mybatis-generator-maven-plugin&lt;/artifactId&gt;</div><div class="line">                &lt;version&gt;1.3.2&lt;/version&gt;</div><div class="line">                &lt;configuration&gt;</div><div class="line">                    &lt;verbose&gt;true&lt;/verbose&gt;</div><div class="line">                    &lt;overwrite&gt;true&lt;/overwrite&gt;</div><div class="line">                &lt;/configuration&gt;</div><div class="line">            &lt;/plugin&gt;</div><div class="line">        &lt;/plugins&gt;</div><div class="line">    &lt;/build&gt;</div><div class="line">&lt;/project&gt;</div></pre></td></tr></table></figure>
<h4 id="在resources-下创建mybatis-config-xml配置文件："><a href="#在resources-下创建mybatis-config-xml配置文件：" class="headerlink" title="在resources 下创建mybatis-config.xml配置文件："></a><strong>在resources 下创建mybatis-config.xml配置文件：</strong></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</div><div class="line">&lt;!DOCTYPE configuration</div><div class="line">  PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot;</div><div class="line">  &quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&gt;</div><div class="line">&lt;configuration&gt;</div><div class="line">	&lt;settings&gt;</div><div class="line">		&lt;!--开启驼峰命名转换--&gt;</div><div class="line">		&lt;setting name=&quot;mapUnderscoreToCamelCase&quot; value=&quot;true&quot;/&gt;</div><div class="line">	&lt;/settings&gt;</div><div class="line">	&lt;!--指定一个包名，MyBatis 会在包名下面搜索需要的 Java Bean--&gt;</div><div class="line">	&lt;typeAliases&gt;</div><div class="line">		&lt;package name=&quot;cn.hfbin.crud.bean&quot;/&gt;</div><div class="line">	&lt;/typeAliases&gt;</div><div class="line">	&lt;!--这个是放mybatis的插件--&gt;</div><div class="line">	&lt;plugins&gt;</div><div class="line">		&lt;!--分页插件--&gt;</div><div class="line">		&lt;plugin interceptor=&quot;com.github.pagehelper.PageInterceptor&quot;&gt;</div><div class="line">			&lt;!--分页参数合理化  --&gt;</div><div class="line">			&lt;property name=&quot;reasonable&quot; value=&quot;true&quot;/&gt;</div><div class="line">		&lt;/plugin&gt;</div><div class="line">	&lt;/plugins&gt;</div><div class="line">&lt;/configuration&gt;</div></pre></td></tr></table></figure>
<h4 id="在resources-下创建applicationContext-xml配置文件："><a href="#在resources-下创建applicationContext-xml配置文件：" class="headerlink" title="在resources 下创建applicationContext.xml配置文件："></a><strong>在resources 下创建applicationContext.xml配置文件：</strong></h4><p>spring的配置文件 ，这里主要配置和业务逻辑有关的 :</p>
<blockquote>
<p>配置数据库数据<br>配置Spring和MyBatis的整合<br>置扫描器，将mybatis接口的实现加入到ioc容器中<br>配置一个可以执行批量的sqlSession<br>配置事务控制<br>开启基于注解的事务，使用xml配置形式的事务<br>配置事务增强，事务如何切入<br>配置MultipartReaolver 文件上传配置<br>………</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</div><div class="line">&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;</div><div class="line">       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</div><div class="line">       xmlns:context=&quot;http://www.springframework.org/schema/context&quot;</div><div class="line">       xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;</div><div class="line">       xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;</div><div class="line">       xsi:schemaLocation=&quot;http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd</div><div class="line">		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd</div><div class="line">		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd</div><div class="line">		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd&quot;&gt;</div><div class="line">    &lt;!--自动扫描包--&gt;</div><div class="line">    &lt;context:component-scan base-package=&quot;cn.hfbin.crud&quot;&gt;</div><div class="line">        &lt;!--除了描控制器不扫描外 其它全部扫描--&gt;</div><div class="line">        &lt;context:exclude-filter type=&quot;annotation&quot;</div><div class="line">                                expression=&quot;org.springframework.stereotype.Controller&quot;/&gt;</div><div class="line">    &lt;/context:component-scan&gt;</div><div class="line"></div><div class="line">    &lt;!-- Spring的配置文件，这里主要配置和业务逻辑有关的 --&gt;</div><div class="line">    &lt;!--=================== 数据源，事务控制，xxx ================--&gt;</div><div class="line">    &lt;context:property-placeholder location=&quot;classpath:dbconfig.properties&quot;/&gt;</div><div class="line">    &lt;bean id=&quot;pooledDataSource&quot; class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot;&gt;</div><div class="line">        &lt;property name=&quot;jdbcUrl&quot; value=&quot;$&#123;jdbc.jdbcUrl&#125;&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;property name=&quot;driverClass&quot; value=&quot;$&#123;jdbc.driverClass&#125;&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;property name=&quot;user&quot; value=&quot;$&#123;jdbc.user&#125;&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;property name=&quot;password&quot; value=&quot;$&#123;jdbc.password&#125;&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!-- 其他配置 --&gt;</div><div class="line">        &lt;!--初始化时获取三个连接，取值应在minPoolSize与maxPoolSize之间。Default: 3 --&gt;</div><div class="line">        &lt;property name=&quot;initialPoolSize&quot; value=&quot;3&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!--连接池中保留的最小连接数。Default: 3 --&gt;</div><div class="line">        &lt;property name=&quot;minPoolSize&quot; value=&quot;3&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!--连接池中保留的最大连接数。Default: 15 --&gt;</div><div class="line">        &lt;property name=&quot;maxPoolSize&quot; value=&quot;20&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --&gt;</div><div class="line">        &lt;property name=&quot;acquireIncrement&quot; value=&quot;3&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0，则缓存被关闭。Default: 0 --&gt;</div><div class="line">        &lt;property name=&quot;maxStatements&quot; value=&quot;8&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --&gt;</div><div class="line">        &lt;property name=&quot;maxStatementsPerConnection&quot; value=&quot;5&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --&gt;</div><div class="line">        &lt;property name=&quot;maxIdleTime&quot; value=&quot;1800&quot;&gt;&lt;/property&gt;</div><div class="line">    &lt;/bean&gt;</div><div class="line"></div><div class="line">    &lt;!--================== 配置和MyBatis的整合=============== --&gt;</div><div class="line">    &lt;bean id=&quot;sqlSessionFactory&quot; class=&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;&gt;</div><div class="line">        &lt;!-- 指定mybatis全局配置文件的位置 --&gt;</div><div class="line">        &lt;property name=&quot;configLocation&quot; value=&quot;classpath:mybatis-config.xml&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;property name=&quot;dataSource&quot; ref=&quot;pooledDataSource&quot;&gt;&lt;/property&gt;</div><div class="line">        &lt;!-- 指定mybatis，mapper文件的位置 --&gt;</div><div class="line">        &lt;property name=&quot;mapperLocations&quot; value=&quot;classpath:mapper/*.xml&quot;&gt;&lt;/property&gt;</div><div class="line">    &lt;/bean&gt;</div><div class="line"></div><div class="line">    &lt;!-- 配置扫描器，将mybatis接口的实现加入到ioc容器中 --&gt;</div><div class="line">    &lt;bean class=&quot;org.mybatis.spring.mapper.MapperScannerConfigurer&quot;&gt;</div><div class="line">        &lt;!--扫描所有dao接口的实现，加入到ioc容器中 --&gt;</div><div class="line">        &lt;property name=&quot;basePackage&quot; value=&quot;cn.hfbin.crud.dao&quot;&gt;&lt;/property&gt;</div><div class="line">    &lt;/bean&gt;</div><div class="line"></div><div class="line">    &lt;!-- 配置一个可以执行批量的sqlSession --&gt;</div><div class="line">    &lt;bean id=&quot;sqlSession&quot; class=&quot;org.mybatis.spring.SqlSessionTemplate&quot;&gt;</div><div class="line">        &lt;constructor-arg name=&quot;sqlSessionFactory&quot; ref=&quot;sqlSessionFactory&quot;&gt;&lt;/constructor-arg&gt;</div><div class="line">        &lt;constructor-arg name=&quot;executorType&quot; value=&quot;BATCH&quot;&gt;&lt;/constructor-arg&gt;</div><div class="line">    &lt;/bean&gt;</div><div class="line">    &lt;!--=============================================  --&gt;</div><div class="line"></div><div class="line">    &lt;!-- ===============事务控制的配置 ================--&gt;</div><div class="line">    &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;&gt;</div><div class="line">        &lt;!--控制住数据源  --&gt;</div><div class="line">        &lt;property name=&quot;dataSource&quot; ref=&quot;pooledDataSource&quot;&gt;&lt;/property&gt;</div><div class="line">    &lt;/bean&gt;</div><div class="line">    &lt;!--开启基于注解的事务，使用xml配置形式的事务（必要主要的都是使用配置式）  --&gt;</div><div class="line">    &lt;aop:config&gt;</div><div class="line">        &lt;!-- 切入点表达式 --&gt;</div><div class="line">        &lt;aop:pointcut expression=&quot;execution(* cn.hfbin.crud.service..*(..))&quot; id=&quot;txPoint&quot;/&gt;</div><div class="line">        &lt;!-- 配置事务增强 --&gt;</div><div class="line">        &lt;aop:advisor advice-ref=&quot;txAdvice&quot; pointcut-ref=&quot;txPoint&quot;/&gt;</div><div class="line">    &lt;/aop:config&gt;</div><div class="line"></div><div class="line">    &lt;!--配置事务增强，事务如何切入  --&gt;</div><div class="line">    &lt;tx:advice id=&quot;txAdvice&quot; transaction-manager=&quot;transactionManager&quot;&gt;</div><div class="line">        &lt;tx:attributes&gt;</div><div class="line">            &lt;!-- 所有方法都是事务方法 --&gt;</div><div class="line">            &lt;tx:method name=&quot;*&quot;/&gt;</div><div class="line">            &lt;!--以get开始的所有方法  --&gt;</div><div class="line">            &lt;tx:method name=&quot;get*&quot; read-only=&quot;true&quot;/&gt;</div><div class="line">        &lt;/tx:attributes&gt;</div><div class="line">    &lt;/tx:advice&gt;</div><div class="line">    &lt;!-- Spring配置文件的核心点（数据源、与mybatis的整合，事务控制） --&gt;</div><div class="line">&lt;/beans&gt;</div></pre></td></tr></table></figure>
<h4 id="在webapp-WEB-INFO-下创建springmvc-servlet-xml配置文件："><a href="#在webapp-WEB-INFO-下创建springmvc-servlet-xml配置文件：" class="headerlink" title="在webapp/WEB-INFO/ 下创建springmvc-servlet.xml配置文件："></a><strong>在webapp/WEB-INFO/ 下创建springmvc-servlet.xml配置文件：</strong></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</div><div class="line">&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;</div><div class="line">	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</div><div class="line">	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;</div><div class="line">	xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;</div><div class="line">	xsi:schemaLocation=&quot;http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd</div><div class="line">		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd</div><div class="line">		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd&quot;&gt;</div><div class="line">	&lt;!-- SpringMVC 的配置文件 ，包含网站跳转的逻辑控制器 --&gt;</div><div class="line">	&lt;context:component-scan base-package=&quot;cn.hfbin&quot; use-default-filters=&quot;false&quot;&gt;</div><div class="line">		&lt;!-- 只扫描控制器 --&gt;</div><div class="line">		&lt;context:include-filter type=&quot;annotation&quot; expression=&quot;org.springframework.stereotype.Controller&quot;/&gt;</div><div class="line">	&lt;/context:component-scan&gt;</div><div class="line">	&lt;!-- 视图解析器 --&gt;</div><div class="line">	&lt;bean class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;</div><div class="line">		&lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/view/&quot;&gt;&lt;/property&gt;</div><div class="line">		&lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot;&gt;&lt;/property&gt;</div><div class="line">	&lt;/bean&gt;</div><div class="line"></div><div class="line">	&lt;!-- 两个标准配置 --&gt;</div><div class="line">	&lt;!-- 将springmvc不能处理的请求交给tomcat --&gt;</div><div class="line">	&lt;mvc:default-servlet-handler/&gt;</div><div class="line">	&lt;!-- 能支持springmvc更高级的一些功能：JSR303校验  ，快捷的ajax ，映射动态请求--&gt;</div><div class="line">	&lt;mvc:annotation-driven/&gt;</div><div class="line">&lt;/beans&gt;</div></pre></td></tr></table></figure>
<h4 id="修改webapp-WEB-INFO-下web-xml配置文件："><a href="#修改webapp-WEB-INFO-下web-xml配置文件：" class="headerlink" title="修改webapp/WEB-INFO/ 下web.xml配置文件："></a><strong>修改webapp/WEB-INFO/ 下web.xml配置文件：</strong></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</div><div class="line">&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</div><div class="line">         xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;</div><div class="line">         xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</div><div class="line">         id=&quot;WebApp_ID&quot; version=&quot;2.5&quot;&gt;</div><div class="line">    &lt;!-- 启动spring容器 --&gt;</div><div class="line">    &lt;!-- needed for ContextLoaderListener --&gt;</div><div class="line">    &lt;context-param&gt;</div><div class="line">        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;</div><div class="line">        &lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;</div><div class="line">    &lt;/context-param&gt;</div><div class="line"></div><div class="line">    &lt;!-- Bootstraps the root web application context before servlet initialization --&gt;</div><div class="line">    &lt;listener&gt;</div><div class="line">        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;</div><div class="line">    &lt;/listener&gt;</div><div class="line"></div><div class="line">    &lt;!-- 启动springmvc的前端控制器 ，拦截所有请求 --&gt;</div><div class="line"></div><div class="line">    &lt;!-- The front controller of this Spring Web application, responsible for</div><div class="line">        handling all application requests --&gt;</div><div class="line">    &lt;servlet&gt;</div><div class="line">        &lt;servlet-name&gt;springmvc&lt;/servlet-name&gt;</div><div class="line">        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;</div><div class="line">        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;</div><div class="line">    &lt;/servlet&gt;</div><div class="line"></div><div class="line">    &lt;!-- Map all requests to the DispatcherServlet for handling --&gt;</div><div class="line">    &lt;servlet-mapping&gt;</div><div class="line">        &lt;servlet-name&gt;springmvc&lt;/servlet-name&gt;</div><div class="line">        &lt;url-pattern&gt;/&lt;/url-pattern&gt;</div><div class="line">    &lt;/servlet-mapping&gt;</div><div class="line">    &lt;!-- 编码过滤器 --&gt;</div><div class="line">    &lt;filter&gt;</div><div class="line">        &lt;filter-name&gt;CharacterEncodingFilter&lt;/filter-name&gt;</div><div class="line">        &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;</div><div class="line">        &lt;init-param&gt;</div><div class="line">            &lt;param-name&gt;encoding&lt;/param-name&gt;</div><div class="line">            &lt;param-value&gt;utf-8&lt;/param-value&gt;</div><div class="line">        &lt;/init-param&gt;</div><div class="line">        &lt;init-param&gt;</div><div class="line">            &lt;param-name&gt;forceRequestEncoding&lt;/param-name&gt;</div><div class="line">            &lt;param-value&gt;true&lt;/param-value&gt;</div><div class="line">        &lt;/init-param&gt;</div><div class="line">        &lt;init-param&gt;</div><div class="line">            &lt;param-name&gt;forceResponseEncoding&lt;/param-name&gt;</div><div class="line">            &lt;param-value&gt;true&lt;/param-value&gt;</div><div class="line">        &lt;/init-param&gt;</div><div class="line">    &lt;/filter&gt;</div><div class="line">    &lt;filter-mapping&gt;</div><div class="line">        &lt;filter-name&gt;CharacterEncodingFilter&lt;/filter-name&gt;</div><div class="line">        &lt;url-pattern&gt;/&lt;/url-pattern&gt;</div><div class="line">    &lt;/filter-mapping&gt;</div><div class="line"></div><div class="line">    &lt;!-- 使用Rest风格的URL --&gt;</div><div class="line">    &lt;filter&gt;</div><div class="line">        &lt;filter-name&gt;HiddenHttpMethodFilter&lt;/filter-name&gt;</div><div class="line">        &lt;filter-class&gt;org.springframework.web.filter.HiddenHttpMethodFilter&lt;/filter-class&gt;</div><div class="line">    &lt;/filter&gt;</div><div class="line">    &lt;filter-mapping&gt;</div><div class="line">        &lt;filter-name&gt;HiddenHttpMethodFilter&lt;/filter-name&gt;</div><div class="line">        &lt;url-pattern&gt;/&lt;/url-pattern&gt;</div><div class="line">    &lt;/filter-mapping&gt;</div><div class="line">&lt;/web-app&gt;</div></pre></td></tr></table></figure>
<p>注意（这里加入了支持Rest风格的URL 的配置）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&lt;filter&gt;</div><div class="line">        &lt;filter-name&gt;HiddenHttpMethodFilter&lt;/filter-name&gt;</div><div class="line">        &lt;filter-class&gt;org.springframework.web.filter.HiddenHttpMethodFilter&lt;/filter-class&gt;</div><div class="line">&lt;/filter&gt;</div><div class="line">&lt;filter-mapping&gt;</div><div class="line">    &lt;filter-name&gt;HiddenHttpMethodFilter&lt;/filter-name&gt;</div><div class="line">    &lt;url-pattern&gt;/&lt;/url-pattern&gt;</div><div class="line">&lt;/filter-mapping&gt;</div></pre></td></tr></table></figure>
<p>到这目前已经整合结束了 只剩下测试了！</p>
<h5 id="由于是新创建的项目Tomcat跟Maven都要重新配。在这教一下大家如何配置Tomcat跟Maven运行配置"><a href="#由于是新创建的项目Tomcat跟Maven都要重新配。在这教一下大家如何配置Tomcat跟Maven运行配置" class="headerlink" title="由于是新创建的项目Tomcat跟Maven都要重新配。在这教一下大家如何配置Tomcat跟Maven运行配置"></a><strong>由于是新创建的项目Tomcat跟Maven都要重新配。在这教一下大家如何配置Tomcat跟Maven运行配置</strong></h5><h4 id="tomcat配置"><a href="#tomcat配置" class="headerlink" title="tomcat配置"></a>tomcat配置</h4><p>第一步</p>
<p><img src="http://img.blog.csdn.net/20171027015015915?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第二步</p>
<p><img src="http://img.blog.csdn.net/20171027020331178?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第三步(第二步双击后出现下面图)<br><img src="http://img.blog.csdn.net/20171027020342153?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第四步</p>
<p><img src="http://img.blog.csdn.net/20171027020354516?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第五步</p>
<p><img src="http://img.blog.csdn.net/20171027020404022?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第六步</p>
<p><img src="http://img.blog.csdn.net/20171027020436211?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"><br>到这完成tomcat 的配置<br><img src="http://img.blog.csdn.net/20171027020654010?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<h4 id="maven运行配置"><a href="#maven运行配置" class="headerlink" title="maven运行配置"></a>maven运行配置</h4><p>具体下载安装以及本地库在这不做详细介绍，maven官网下载地址<a href="http://maven.apache.org/download.cgi" target="_blank" rel="external">http://maven.apache.org/download.cgi</a></p>
<p>idea跟maven的配置在这不做详细介绍，在这只做<strong><em>运行配置</em></strong></p>
<p>第一步</p>
<p><img src="http://img.blog.csdn.net/20171027022437583?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第二步</p>
<p><img src="http://img.blog.csdn.net/20171027022448076?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>第三步</p>
<p><img src="http://img.blog.csdn.net/20171027022458171?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>maven运行配置完成</p>
<p><img src="http://img.blog.csdn.net/20171027022510544?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>现在两个都配置好了</p>
<p>把maven跑起来<br><img src="http://img.blog.csdn.net/20171027023454691?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>这时把Tomcat也跑起来 ，此时报了一个错，就是没有找到mapper/*.xml文件。这时打开applicationContext.xml,找到对应错误的行数 。<br>如下图：</p>
<p><img src="http://img.blog.csdn.net/20171027095142552?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>把提示错误这行注释掉，再重启Tomcat即可</p>
<p><img src="http://img.blog.csdn.net/20171027095656598?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>到这为止可以简单的测试一下前端是否可以顺利的与后台交互</p>
<p>在webapp/WEB-INFO/ 下创建一个views文件夹在里面新建一个jsp页面<br>index.jsp</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">&lt;%--</div><div class="line">  Created by IntelliJ IDEA.</div><div class="line">  User: HuangFuBin</div><div class="line">  Date: 2017/10/27</div><div class="line">  Time: 2:28</div><div class="line">  To change this template use File | Settings | File Templates.</div><div class="line">--%&gt;</div><div class="line">&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;</div><div class="line">&lt;html&gt;</div><div class="line">&lt;head&gt;</div><div class="line">    &lt;title&gt;Title&lt;/title&gt;</div><div class="line">&lt;/head&gt;</div><div class="line">&lt;body&gt;</div><div class="line">      &lt;h1 style=&quot;text-align: center ; margin-top: 100px;&quot;&gt;Spring + SpringMVC + Mybatis 整合完成&lt;/h1&gt;</div><div class="line">&lt;/body&gt;</div><div class="line">&lt;/html&gt;</div></pre></td></tr></table></figure>
<p>在cn.hfbin.controller包下创建一个IndexController类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">package cn.hfbin.crud.controller;</div><div class="line"></div><div class="line">import org.springframework.stereotype.Controller;</div><div class="line">import org.springframework.web.bind.annotation.RequestMapping;</div><div class="line"></div><div class="line">@Controller</div><div class="line">public class IndexController &#123;</div><div class="line"></div><div class="line">    @RequestMapping(&quot;/index&quot;)</div><div class="line">    public String index()&#123;</div><div class="line">        System.out.println(&quot;进入Controller&quot;);</div><div class="line">        return &quot;index&quot;;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>如图</p>
<p><img src="http://img.blog.csdn.net/20171027101137204?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>重启一下tomcat 到页面进行测试，测试结果如下</p>
<p><img src="http://img.blog.csdn.net/20171027101812625?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>其实到这只能说明一点Spring跟SpringMVC整合完美成功！！！！</p>
<h4 id="要跟Mybatis整合还是需要一个案例讲解，在后面的时间段里我会通过讲解ssm的一个crud来详细的介绍Mybatis"><a href="#要跟Mybatis整合还是需要一个案例讲解，在后面的时间段里我会通过讲解ssm的一个crud来详细的介绍Mybatis" class="headerlink" title="要跟Mybatis整合还是需要一个案例讲解，在后面的时间段里我会通过讲解ssm的一个crud来详细的介绍Mybatis."></a>要跟Mybatis整合还是需要一个案例讲解，在后面的时间段里我会通过讲解ssm的一个crud来详细的介绍Mybatis.</h4><h4 id="上面只是介绍了mybatis跟spring配置，在此希望你能关注我，下一篇文章会着重的介绍mybatis。"><a href="#上面只是介绍了mybatis跟spring配置，在此希望你能关注我，下一篇文章会着重的介绍mybatis。" class="headerlink" title="上面只是介绍了mybatis跟spring配置，在此希望你能关注我，下一篇文章会着重的介绍mybatis。"></a>上面只是介绍了mybatis跟spring配置，在此希望你能关注我，下一篇文章会着重的介绍mybatis。</h4><p><strong>如果你等不及我更新可以先到我的GiuHub上面看我的源码</strong>  <a href="https://github.com/hfbin/SSM-crud" target="_blank" rel="external">https://github.com/hfbin/SSM-crud</a><br><img src="http://img.blog.csdn.net/20171027110002365?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<h3 id="效果图："><a href="#效果图：" class="headerlink" title="效果图："></a><strong>效果图：</strong></h3><p><img src="http://img.blog.csdn.net/20171027110436398?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzM1MjQxNTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>下一章会着重介绍mybatis</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/weixinpay.png" alt="HuangFuBin WeChat Pay"/>
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="HuangFuBin Alipay"/>
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/SSM/" <i class="fa fa-tag"></i> SSM</a>
          
            <a href="/tags/Spring/" <i class="fa fa-tag"></i> Spring</a>
          
            <a href="/tags/SpringMVC/" <i class="fa fa-tag"></i> SpringMVC</a>
          
            <a href="/tags/Mybatis/" <i class="fa fa-tag"></i> Mybatis</a>
          
            <a href="/tags/Maven/" <i class="fa fa-tag"></i> Maven</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/10/31/基于liunx的git操作/" rel="next" title="基于liunx的git操作">
                <i class="fa fa-chevron-left"></i> 基于liunx的git操作
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/11/01/常见配置redis.conf介绍 /" rel="prev" title="常见配置redis.conf介绍">
                常见配置redis.conf介绍 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_tsina"></a>
  <!--<a class="jiathis_button_tqq"></a>-->
  
  <!--<a class="jiathis_button_douban"></a>-->
  <!--<a class="jiathis_button_renren"></a>-->
  <a class="jiathis_button_qzone"></a>
  <!--<a class="jiathis_button_kaixin001"></a>-->
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="SOHUCS"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://avatars3.githubusercontent.com/u/26451830?s=400&u=fac2b4c7903b3ad1210b530e2d18e42fcb410b0a&v=4"
               alt="HuangFuBin" />
          <p class="site-author-name" itemprop="name">HuangFuBin</p>
           
              <p class="site-description motion-element" itemprop="description">My friend promised me to go if I had the road</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hfbin" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                    
                      GitHub
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=DmZ7b2BpaHtsZ2AgbGF9fU5oYXZjb2diIG1hYw" target="_blank" title="E-Mail">
                  
                    <i class="fa fa-fw fa-envelope"></i>
                  
                    
                      E-Mail
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/3904243687/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                    
                      Weibo
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.hfbin.cn/" title="Title" target="_blank">Title</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#在整合之前先介绍一下Maven"><span class="nav-number">1.</span> <span class="nav-text">在整合之前先介绍一下Maven:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Spring-SpringMVC-Mybatis基本概念"><span class="nav-number">2.</span> <span class="nav-text">Spring SpringMVC Mybatis基本概念</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#SSM整合在这使用的开发工具是idea"><span class="nav-number">3.</span> <span class="nav-text">SSM整合在这使用的开发工具是idea</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#先从pom-xml文件入手"><span class="nav-number">3.1.</span> <span class="nav-text">先从pom.xml文件入手</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#在resources-下创建mybatis-config-xml配置文件："><span class="nav-number">4.</span> <span class="nav-text">在resources 下创建mybatis-config.xml配置文件：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#在resources-下创建applicationContext-xml配置文件："><span class="nav-number">5.</span> <span class="nav-text">在resources 下创建applicationContext.xml配置文件：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#在webapp-WEB-INFO-下创建springmvc-servlet-xml配置文件："><span class="nav-number">6.</span> <span class="nav-text">在webapp/WEB-INFO/ 下创建springmvc-servlet.xml配置文件：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#修改webapp-WEB-INFO-下web-xml配置文件："><span class="nav-number">7.</span> <span class="nav-text">修改webapp/WEB-INFO/ 下web.xml配置文件：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#由于是新创建的项目Tomcat跟Maven都要重新配。在这教一下大家如何配置Tomcat跟Maven运行配置"><span class="nav-number">7.1.</span> <span class="nav-text">由于是新创建的项目Tomcat跟Maven都要重新配。在这教一下大家如何配置Tomcat跟Maven运行配置</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#tomcat配置"><span class="nav-number">8.</span> <span class="nav-text">tomcat配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#maven运行配置"><span class="nav-number">9.</span> <span class="nav-text">maven运行配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#要跟Mybatis整合还是需要一个案例讲解，在后面的时间段里我会通过讲解ssm的一个crud来详细的介绍Mybatis"><span class="nav-number">10.</span> <span class="nav-text">要跟Mybatis整合还是需要一个案例讲解，在后面的时间段里我会通过讲解ssm的一个crud来详细的介绍Mybatis.</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#上面只是介绍了mybatis跟spring配置，在此希望你能关注我，下一篇文章会着重的介绍mybatis。"><span class="nav-number">11.</span> <span class="nav-text">上面只是介绍了mybatis跟spring配置，在此希望你能关注我，下一篇文章会着重的介绍mybatis。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#效果图："><span class="nav-number"></span> <span class="nav-text">效果图：</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright display_zhanzhang" style="text-align: center !important;">
  <span class="author" itemprop="copyrightHolder">桂ICP备16010161号</span>
</div>
<div class="copyright" style="text-align: center !important;">
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">HuangFuBin</span>
</div>
<div class="copyright" style="text-align: center !important;">
	
	<div class="powered-by" style="text-align: center !important;">
	  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
	</div>

	<div class="theme-info" style="text-align: center !important;">
	  Theme -
	  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
		NexT.Mist
	  </a>
	</div>
	
</div>
<div class="copyright display_zhanzhang"  style="text-align: center !important;">
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1266987503'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1266987503%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
</div>
        

<div class="busuanzi-count">
  

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>


        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cysX5MNF0';
      var conf = '504c8a8b8a5aff5f06dd805c527bbf0f';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  



  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.2"></script>



  

  

  

  

  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.2"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.2"></script>


  

  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
</body>

</html>
